package com.goldsprite.gameframeworks.ecs.component;

import com.badlogic.gdx.graphics.Color;
import com.goldsprite.gameframeworks.ecs.system.renderer.Gizmos;
import com.goldsprite.gameframeworks.simplephys.shape.*;
import com.goldsprite.gameframeworks.utils.math.Vector2;

public class RectColliderComponent extends ColliderComponent<PhysRect> {
	private Vector2 halfSize = Vector2.Half();
	private PhysRect rect = new PhysRect(0, 0, halfSize.x, halfSize.y);

	public Vector2 getHalfSize() {
		return halfSize;
	}
	public void setSize(float width, float height) {
		this.halfSize.set(width / 2f, height / 2f);
	}

	Vector2 tmpVec2 = new Vector2();
	@Override
	public PhysRect getShape() {
		Vector2 leftDownPos = tmpVec2.set(getWorldPosition()).sub(halfSize);
		rect.set(leftDownPos.x, leftDownPos.y, halfSize.x*2, halfSize.y*2);

		rect.pos.set(getWorldPosition());//中心位置
		rect.vel.set(rigi.getVelocity());
		rect.hx = halfSize.x;
		rect.hy = halfSize.y;
		return rect;
	}

	@Override
	public ShapeType getShapeType() {
		return ShapeType.Rect;
	}

	@Override
	public void drawGizmos() {
		float cx = getWorldRenderPosition().x;
		float cy = getWorldRenderPosition().y;
		float width = halfSize.x * 2;
		float height = halfSize.y * 2;
		Gizmos.setColor(PhysColor.Default.val);
		Gizmos.rect(cx, cy, width, height);
	}
}
